package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAdApply;
import com.ruoyi.system.service.ISysAdApplyService;
import com.ruoyi.system.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/apply")
public class SysAdApplyController extends BaseController
{
    @Autowired
    private ISysAdApplyService sysAdApplyService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAdApply sysAdApply)
    {
        startPage();
        List<SysAdApply> list = sysAdApplyService.selectSysAdApplyList(sysAdApply);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAdApply sysAdApply)
    {
        List<SysAdApply> list = sysAdApplyService.selectSysAdApplyList(sysAdApply);
        ExcelUtil<SysAdApply> util = new ExcelUtil<SysAdApply>(SysAdApply.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysAdApplyService.selectSysAdApplyById(id));
    }

    @Resource
    private MailService mailService;

    /**
     * 新增【请填写功能名称】
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysAdApply sysAdApply)
    {
        if (sysAdApplyService.insertSysAdApply(sysAdApply) > 0) {
            String mailRecipient = "kathy.chan@megatalents.com.hk,jojo.wang@jobslink.com.hk,paul.luo@megasolutions.com.hk";
            String str = "UserName: " + sysAdApply.getName() +
                    "<br >Mobile: " + sysAdApply.getContact() +
                    "<br > Age:" + sysAdApply.getAge() +
                    "<br > 学历:<br >" + sysAdApply.getDegree() +
                    "<br > 工作/管理经验:<br >" + sysAdApply.getWorks() +
                    "<br > 额外加分项:<br >" + sysAdApply.getScorese() +
                    "<br > 其它想要咨询的问题:<br >" + sysAdApply.getOther() +
                    "<br > 是否需要申报税务服务:<br >" + sysAdApply.getTax() +
                    "<br > 是否需要在香港注册公司:<br >" + sysAdApply.getCompany() +
                    "<br > 是否需要在香港找工作:<br >" + sysAdApply.getJob() + ",行业:" + sysAdApply.getIndustry();
            mailService.sendAppendixMailAlarm(mailRecipient,
                    "来自小红书提交申请", str);
            return toAjax(1);
        } else {
            return toAjax(0);
        }

    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAdApply sysAdApply)
    {
        return toAjax(sysAdApplyService.updateSysAdApply(sysAdApply));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysAdApplyService.deleteSysAdApplyByIds(ids));
    }
}
